package com.koron.css2.systemManage.servlet;

import com.koron.css2.ApplicationConfig;
import com.koron.css2.ServerInterface;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.systemManage.dto.UserAuthorityDto;
import com.koron.css2.systemManage.service.UserService;
import com.koron.util.Constant;
import com.koron.util.SpringContextHolder;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

/**
 * 查询当前用户权限信息
 *
 * @author 59532
 */
public class UserAuthority implements ServerInterface {

    private static Logger log = LogManager.getLogger(UserAuthority.class);

    private UserService userService = SpringContextHolder.getBean(UserService.class);

    @Override
    public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
        MessageBean<UserAuthorityDto> msg = MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "查询成功", UserAuthorityDto.class);
        try {
            UserAuthorityDto userAuthority = userService.getUserAuthority(factory, userInfo, ApplicationConfig.getAppCustomerAppid(), req.getToken());
            msg.setData(userAuthority);
        } catch (Exception e) {
            log.error("查询当前用户权限信息出错：" + e, e);
            msg.setCode(Constant.MESSAGE_INT_FAIL);
            msg.setDescription(e.getMessage());
        }
        return msg;
    }
}
